package restructure.chapter06;

/**
 * @Description
 * @Date 2021/9/19
 * @Created by Jonathan
 */
public class Gamma {
    private final Account _account;
    private int inputValue;
    private int quantity;
    private int yearToDate;
    private int importantValue1;
    private int importantValue2;
    private int importantValue3;


    public Gamma(Account source, int inputArg, int quantityArg, int yearToDateArg) {
        this._account = source;
        this.inputValue = inputArg;
        this.quantity = quantityArg;
        this.yearToDate = yearToDateArg;
    }

    /**
     * 把原本的函数搬到compute()。函数中任何调用Account类的地方，都必须改为使用_account字段
     * <br/>
     * 这样可以轻松的对compute()函数采取Extract Method，不必担心参数传递的问题
     */
    int compute() {
        importantValue1 = (inputValue * quantity) + _account.delta();
        importantValue2 = (inputValue * yearToDate) + 100;
        importantThing();
        importantValue3 = importantValue2 * 7;
        return importantValue3 - 2 * importantValue1;
    }

    private void importantThing() {
        if ((yearToDate - importantValue1) > 100) {
            importantValue2 -= 20;
        }
    }
}
